home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / nfs / nfswatch4.0 / RCS / netaddr.c,v < prev    next >
Encoding:
Text File  |  1993-03-01  |  7.8 KB  |  444 lines

  1. head    4.0;
  2. access;
  3. symbols;
  4. locks; strict;
  5. comment    @ * @;
  6.  
  7.  
  8. 4.0
  9. date    93.03.01.19.59.00;    author davy;    state Exp;
  10. branches;
  11. next    3.4;
  12.  
  13. 3.4
  14. date    93.02.24.17.44.45;    author davy;    state Exp;
  15. branches;
  16. next    3.3;
  17.  
  18. 3.3
  19. date    93.01.16.19.08.59;    author davy;    state Exp;
  20. branches;
  21. next    3.2;
  22.  
  23. 3.2
  24. date    93.01.15.19.33.39;    author davy;    state Exp;
  25. branches;
  26. next    3.1;
  27.  
  28. 3.1
  29. date    93.01.13.20.18.17;    author davy;    state Exp;
  30. branches;
  31. next    3.0;
  32.  
  33. 3.0
  34. date    91.01.23.08.23.06;    author davy;    state Exp;
  35. branches;
  36. next    1.2;
  37.  
  38. 1.2
  39. date    90.08.17.15.47.24;    author davy;    state Exp;
  40. branches;
  41. next    1.1;
  42.  
  43. 1.1
  44. date    88.11.29.11.20.35;    author davy;    state Released;
  45. branches;
  46. next    ;
  47.  
  48.  
  49. desc
  50. @NFSWATCH - monitor Network File System traffic on the network.
  51. @
  52.  
  53.  
  54. 4.0
  55. log
  56. @NFSWATCH Version 4.0.
  57. @
  58. text
  59. @#ifndef lint
  60. static char *RCSid = "$Header: /home/harbor/davy/system/nfswatch/RCS/netaddr.c,v 3.4 1993/02/24 17:44:45 davy Exp davy $";
  61. #endif
  62.  
  63. #include "os.h"
  64.  
  65. /*
  66.  * netaddr.c - routines for working with network addresses.
  67.  *
  68.  * David A. Curry                Jeffrey C. Mogul
  69.  * Purdue University                Digital Equipment Corporation
  70.  * Engineering Computer Network            Western Research Laboratory
  71.  * 1285 Electrical Engineering Building        250 University Avenue
  72.  * West Lafayette, IN 47907-1285        Palo Alto, CA 94301
  73.  * davy@@ecn.purdue.edu                mogul@@decwrl.dec.com
  74.  *
  75.  * $Log: netaddr.c,v $
  76.  * Revision 3.4  1993/02/24  17:44:45  davy
  77.  * Added -auth mode, changes to -proc mode, -map option, -server option.
  78.  *
  79.  * Revision 3.3  1993/01/16  19:08:59  davy
  80.  * Corrected Jeff's address.
  81.  *
  82.  * Revision 3.2  1993/01/15  19:33:39  davy
  83.  * Miscellaneous cleanups.
  84.  *
  85.  * Revision 3.1  1993/01/13  20:18:17  davy
  86.  * Put in OS-specific define scheme, and merged in Tim Hudson's code for
  87.  * SGI systems (as yet untested).
  88.  *
  89.  * Revision 3.0  1991/01/23  08:23:06  davy
  90.  * NFSWATCH Version 3.0.
  91.  *
  92.  * Revision 1.2  90/08/17  15:47:24  davy
  93.  * NFSWATCH Version 2.0.
  94.  * 
  95.  * Revision 1.1  88/11/29  11:20:35  davy
  96.  * NFSWATCH Release 1.0
  97.  * 
  98.  */
  99. #include <sys/param.h>
  100. #include <netdb.h>
  101. #include <stdio.h>
  102.  
  103. #include "nfswatch.h"
  104. #include "externs.h"
  105.  
  106. /*
  107.  * get_net_addrs - get network addresses of source and destination
  108.  *           hosts, along with official host names.
  109.  */
  110. void
  111. get_net_addrs()
  112. {
  113.     register int n;
  114.     char *inet_ntoa();
  115.     register char **cp;
  116.     struct hostent *hp;
  117.  
  118.     /*
  119.      * Look up the local host.
  120.      */
  121.     if ((hp = gethostbyname(myhost)) == NULL) {
  122.         (void) fprintf(stderr, "%s: %s: unknown host.\n", pname,
  123.             myhost);
  124.         finish(-1);
  125.     }
  126.  
  127.     /*
  128.      * Save the official host name.
  129.      */
  130.     (void) strcpy(myhost, hp->h_name);
  131.  
  132.     /*
  133.      * If one was specified, look up the destination host.
  134.      * Otherwise, we can use what we have.
  135.      */
  136.     if (allflag) {
  137.         (void) sprintf(dsthost, "all hosts");
  138.     }
  139.     else if (dstflag) {
  140.         if ((hp = gethostbyname(dsthost)) == NULL) {
  141.             (void) fprintf(stderr, "%s: %s: unknown host.\n", pname,
  142.                 dsthost);
  143.             finish(-1);
  144.         }
  145.  
  146.         /*
  147.          * Save the official host name.
  148.          */
  149.         (void) strcpy(dsthost, hp->h_name);
  150.     }
  151.     else {
  152.         /*
  153.          * Host name is the same as the local
  154.          * host.
  155.          */
  156.         (void) strcpy(dsthost, myhost);
  157.     }
  158.  
  159.     /*
  160.      * Copy destination host's network addresses.
  161.      */
  162.     n = 0;
  163.     (void) bzero((char *) dstaddrs, MAXHOSTADDR * sizeof(u_long));
  164.  
  165.     for (cp = hp->h_addr_list; *cp != NULL; cp++) {
  166.         if (n >= MAXHOSTADDR)
  167.             break;
  168.  
  169.         (void) bcopy(*cp, (char *) &dstaddrs[n], hp->h_length);
  170.         n++;
  171.     }
  172.  
  173.     /*
  174.      * If they specified a server host, get its addresses.
  175.      */
  176.     if (serverflag) {
  177.         if ((hp = gethostbyname(serverhost)) == NULL) {
  178.             fprintf(stderr, "%s: %s: unknown host.\n", pname,
  179.                 serverhost);
  180.             finish(-1);
  181.         }
  182.  
  183.         /*
  184.          * Save the official host name.
  185.          */
  186.         (void) strcpy(serverhost, hp->h_name);
  187.  
  188.         /*
  189.          * Copy the server's network addresses.
  190.          */
  191.         n = 0;
  192.         (void) bzero((char *) serveraddrs, MAXHOSTADDR *
  193.                  sizeof(u_long));
  194.  
  195.         for (cp = hp->h_addr_list; *cp != NULL; cp++) {
  196.             if (n >= MAXHOSTADDR)
  197.                 break;
  198.  
  199.             (void) bcopy(*cp, (char *) &serveraddrs[n],
  200.                      hp->h_length);
  201.             n++;
  202.         }
  203.     }
  204.  
  205.     /*
  206.      * If they didn't specify a source host,
  207.      * we're done.
  208.      */
  209.     if (!srcflag)
  210.         return;
  211.  
  212.     /*
  213.      * Look up the source host.
  214.      */
  215.     if ((hp = gethostbyname(srchost)) == NULL) {
  216.         (void) fprintf(stderr, "%s: %s: unknown host.\n", pname,
  217.             srchost);
  218.         finish(-1);
  219.     }
  220.  
  221.     /*
  222.      * Save the official host name.
  223.      */
  224.     (void) strcpy(srchost, hp->h_name);
  225.  
  226.     /*
  227.      * Copy source host's network addresses.
  228.      */
  229.     n = 0;
  230.     (void) bzero((char *) srcaddrs, MAXHOSTADDR * sizeof(u_long));
  231.  
  232.     for (cp = hp->h_addr_list; *cp != NULL; cp++) {
  233.         if (n >= MAXHOSTADDR)
  234.             break;
  235.  
  236.         (void) bcopy(*cp, (char *) &srcaddrs[n], hp->h_length);
  237.         n++;
  238.     }
  239. }
  240.  
  241. /*
  242.  * want_packet - determine if we're interested in a packet by examining
  243.  *         its source and destination addresses.
  244.  */
  245. int
  246. want_packet(src, dst)
  247. u_long src, dst;
  248. {
  249.     register int i, want;
  250.  
  251.     want = FALSE;
  252.  
  253.     /*
  254.      * Check that the source or destination is the server.
  255.      */
  256.     if (serverflag) {
  257.         for (i=0; (serveraddrs[i] != 0) && (i < MAXHOSTADDR); i++) {
  258.             if (!bcmp((char *) &src, (char *) &serveraddrs[i],
  259.                   sizeof(u_long)) ||
  260.                 !bcmp((char *) &dst, (char *) &serveraddrs[i],
  261.                   sizeof(u_long))) {
  262.                 want = TRUE;
  263.                 break;
  264.             }
  265.         }
  266.  
  267.         if (want && allflag)
  268.             thisdst = dst;
  269.  
  270.         return(want);
  271.     }
  272.      
  273.     /*
  274.      * Any source or destination is okay.
  275.      */
  276.     if (allflag) {
  277.         thisdst = dst;
  278.         return(TRUE);
  279.     }
  280.  
  281.     /*
  282.      * Check source address first.
  283.      */
  284.     if (srcflag) {
  285.         for (i = 0; (srcaddrs[i] != 0) && (i < MAXHOSTADDR); i++) {
  286.             if (!bcmp((char *) &src, (char *) &srcaddrs[i],
  287.                 sizeof(u_long))) {
  288.                 want = TRUE;
  289.                 break;
  290.             }
  291.         }
  292.  
  293.         /*
  294.          * If it's not from our source, we
  295.          * don't even need to check the destination.
  296.          */
  297.         if (!want)
  298.             return(FALSE);
  299.     }
  300.  
  301.     want = FALSE;
  302.  
  303.     /*
  304.      * Check destination address.
  305.      */
  306.     for (i = 0; (dstaddrs[i] != 0) && (i < MAXHOSTADDR); i++) {
  307.         if (!bcmp((char *) &dst, (char *) &dstaddrs[i],
  308.             sizeof(u_long))) {
  309.             want = TRUE;
  310.             break;
  311.         }
  312.     }
  313.  
  314.     return(want);
  315. }
  316. @
  317.  
  318.  
  319. 3.4
  320. log
  321. @Added -auth mode, changes to -proc mode, -map option, -server option.
  322. @
  323. text
  324. @d2 1
  325. a2 1
  326. static char *RCSid = "$Header: /home/harbor/davy/system/nfswatch/RCS/netaddr.c,v 3.3 1993/01/16 19:08:59 davy Exp davy $";
  327. d18 3
  328. @
  329.  
  330.  
  331. 3.3
  332. log
  333. @Corrected Jeff's address.
  334. @
  335. text
  336. @d2 1
  337. a2 1
  338. static char *RCSid = "$Header: /home/harbor/davy/system/nfswatch/RCS/netaddr.c,v 3.2 1993/01/15 19:33:39 davy Exp davy $";
  339. d18 3
  340. d113 32
  341. d190 2
  342. d193 20
  343. a218 2
  344.  
  345.     want = FALSE;
  346. @
  347.  
  348.  
  349. 3.2
  350. log
  351. @Miscellaneous cleanups.
  352. @
  353. text
  354. @d2 1
  355. a2 1
  356. static char *RCSid = "$Header: /home/harbor/davy/system/nfswatch/RCS/netaddr.c,v 3.1 1993/01/13 20:18:17 davy Exp davy $";
  357. d13 1
  358. a13 1
  359.  * 1285 Electrical Engineering Building        100 Hamilton Avenue
  360. d18 3
  361. @
  362.  
  363.  
  364. 3.1
  365. log
  366. @Put in OS-specific define scheme, and merged in Tim Hudson's code for
  367. SGI systems (as yet untested).
  368. @
  369. text
  370. @d2 1
  371. a2 1
  372. static char *RCSid = "$Header: /home/harbor/davy/system/nfswatch/RCS/netaddr.c,v 3.0 1991/01/23 08:23:06 davy Exp davy $";
  373. d5 2
  374. d11 5
  375. a15 5
  376.  * SRI International                Digital Equipment Corporation
  377.  * 333 Ravenswood Avenue            Western Research Laboratory
  378.  * Menlo Park, CA 94025                100 Hamilton Avenue
  379.  * davy@@erg.sri.com                Palo Alto, CA 94301
  380.  *                        mogul@@decwrl.dec.com
  381. d18 4
  382. a35 1
  383. #include "os.h"
  384. @
  385.  
  386.  
  387. 3.0
  388. log
  389. @NFSWATCH Version 3.0.
  390. @
  391. text
  392. @d2 1
  393. a2 1
  394. static char *RCSid = "$Header: /tmp_mnt/net/sparky.a/davy/system/nfswatch/RCS/netaddr.c,v 1.2 90/08/17 15:47:24 davy Exp Locker: davy $";
  395. d15 4
  396. a18 1
  397.  * $Log:    netaddr.c,v $
  398. d30 1
  399. @
  400.  
  401.  
  402. 1.2
  403. log
  404. @NFSWATCH Version 2.0.
  405. @
  406. text
  407. @d2 1
  408. a2 1
  409. static char *RCSid = "$Header: /tmp_mnt/net/sparky.a/davy/system/nfswatch/RCS/netaddr.c,v 1.1 88/11/29 11:20:35 davy Released Locker: davy $";
  410. d8 6
  411. a13 5
  412.  * David A. Curry
  413.  * SRI International
  414.  * 333 Ravenswood Avenue
  415.  * Menlo Park, CA 94025
  416.  * davy@@itstd.sri.com
  417. d16 3
  418. @
  419.  
  420.  
  421. 1.1
  422. log
  423. @NFSWATCH Release 1.0
  424. @
  425. text
  426. @d2 1
  427. a2 1
  428. static char *RCSid = "$Header$";
  429. d9 4
  430. a12 5
  431.  * Research Institute for Advanced Computer Science
  432.  * Mail Stop 230-5
  433.  * NASA Ames Research Center
  434.  * Moffett Field, CA 94035
  435.  * davy@@riacs.edu
  436. d14 4
  437. a17 1
  438.  * $Log$
  439. d56 4
  440. a59 1
  441.     if (dstflag) {
  442. d138 8
  443. @
  444.